<template>
  <PageWrapper>
    <BasicTable @register="registerTable">
      <template #tableTitle> </template>
      <template #bodyCell="{ column, record, text }">
        <template v-if="column.dataIndex === 'name'">
          <EllipsisTooltip :title="record.name" :width="260">
            <span class="global-primary-text" @click="viewDetail(record)">
              {{ record.name }}
            </span>
          </EllipsisTooltip>
        </template>
        <template v-else-if="column.dataIndex === 'nameType'">
          <span class="global-stop-status" v-if="record.nameType === 0">灰度</span>
          <span class="global-active-status" v-else-if="record.nameType === 1">生产</span>
        </template>
      </template>
    </BasicTable>
    <MirroringDetail @register="tenantMirroringRegister" />
  </PageWrapper>
</template>

<script lang="ts" setup>
import { reactive, ref, computed, unref } from 'vue'
import PageWrapper from '@/components/PageWrapper/index.vue'
import { BasicTable, useTable } from '@/components/Table'
import { getMirroringBasicColumns, getSearchFormConfig } from './dataSource'
import { useDrawer } from '@/components/Drawer'
import EllipsisTooltip from '@/components/EllipsisTooltip/index.vue'
import MirroringDetail from './components/MirroringDetail.vue'
import { operateActionType, operateTxtType, constantMap } from '@/types/enum'
import { MirroringRecord } from '@/types/deployUpgrade'
import { message } from 'ant-design-vue'
import api from '@/api'
const { listReposDetails } = api

const [registerTable, { reload, setPagination, getForm }] = useTable({
  api: listReposDetails,
  columns: getMirroringBasicColumns(),
  useSearchForm: true,
  formConfig: getSearchFormConfig(),
  // afterFetch: afterDataFetch,
  beforeFetch: beforeParamsFetch,
  fetchSetting: {
    listField: 'list'
  },
  scroll: { y: constantMap.tableYHeight, x: constantMap.tableXWidth }
})

const [tenantMirroringRegister, { openDrawer: MirroringOpenDrawer }] = useDrawer()

// 表格返回数据处理
// function afterDataFetch(data: MirroringRecord[]) {
//   let formData = getForm().getFieldsValue()
//   if (formData && formData.name && data && data.length) {
//     return data.filter((item: MirroringRecord) => item.name && item.name.indexOf(formData.name) > -1)
//   } else {
//     return data
//   }
// }
// 请求参数处理
function beforeParamsFetch(params: Recordable) {
  const { page, name, namespace } = params
  let paramsData = {
    limit: page.pageSize,
    offset: (page.pageNo - 1) * page.pageSize,
    name,
    namespace
  }
  return paramsData
}
// 镜像详情
const viewDetail = (record: MirroringRecord) => {
  MirroringOpenDrawer(true, {
    record
  })
}
</script>

<style lang="less" scoped></style>
